package cn.chrisx.drad.audiencenetwork;

import android.content.Context;

import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.InterstitialAd;
import com.facebook.ads.InterstitialAdListener;

import cn.chrisx.drad.core.DrAdError;

/**
 * @author Jzfox <jz_boy@163.com>
 * @version 1.0
 * @date 2018/9/26 13:46
 * @description
 * @copyright ©2018 www.jzfox.net All rights reserved.
 */
public class InterstitialImpl extends BaseAd implements InterstitialAdListener {

    private InterstitialAd interstitialAd;

    @Override
    public boolean loadAd(Context context) {

        if (interstitialAd == null) {
            interstitialAd = new InterstitialAd(context, drAdConfig.getAdUnitId());
            interstitialAd.setAdListener(this);
        }

        interstitialAd.loadAd();

        return true;
    }

    @Override
    public boolean show() {
        return isValid() && interstitialAd.show();
    }

    @Override
    public boolean isValid() {
        return interstitialAd != null && interstitialAd.isAdLoaded();
    }


    @Override
    public void onDestroy(Context context) {
        if (interstitialAd != null) interstitialAd.destroy();
    }

    @Override
    public void onInterstitialDisplayed(Ad ad) {
        onAdShow();
    }

    @Override
    public void onInterstitialDismissed(Ad ad) {
        onAdDismiss();
    }
}
